# _*_ encoding:utf-8 _*_
"""
最上级的模型
用户操作的模型
"""
# python 源生包
from datetime import datetime

# 第三方库
from django.db import models

# 自定义的包
from users.models import UserProfile
from courses.models import Course
# Create your models here.


# 用户咨询
class UserAsk(models.Model):
    name = models.CharField(max_length=20, verbose_name="姓名")
    mobile = models.CharField(max_length=11, verbose_name="手机")
    course_name = models.CharField(max_length=50, verbose_name="课程名")
    add_time = models.DateField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "用户咨询"
        verbose_name_plural = verbose_name


# 课程评论
class CourseComments(models.Model):
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.DO_NOTHING)  # 外键
    course = models.ForeignKey(Course, verbose_name="课程", on_delete=models.DO_NOTHING)  # 外键
    comments = models.CharField(max_length=200, verbose_name="评论")
    add_time = models.DateField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "课程评论"
        verbose_name_plural = verbose_name


# 用户收藏
class UserFavorite(models.Model):
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.DO_NOTHING)  # 外键
    fav_id = models.IntegerField(default=0, verbose_name="数据ID")
    fav_type = models.IntegerField(choices=((1, "课程"), (2, "课程机构"), (3, "教师")), default=1, verbose_name="收藏类型")
    add_time = models.DateField(default=datetime.now, verbose_name="添加时间")

    class Meta:
        verbose_name = "用户收藏"
        verbose_name_plural = verbose_name


# 用户消息
class UserMessage(models.Model):
    user = models.IntegerField(default=0, verbose_name="接收用户")  # 0为全体消息, 其它则为单独发送
    message = models.CharField(max_length=500, verbose_name="消息内容")
    has_read = models.BooleanField(default=False, verbose_name="是否已读")
    add_time = models.DateField(default=datetime.now, verbose_name="发送时间")

    class Meta:
        verbose_name = "用户消息"
        verbose_name_plural = verbose_name


# 用户学习的课程
class UserCourse(models.Model):
    user = models.ForeignKey(UserProfile, verbose_name="用户", on_delete=models.DO_NOTHING)  # 外键
    course = models.ForeignKey(Course, verbose_name="课程", on_delete=models.DO_NOTHING)  # 外键
    add_time = models.DateField(default=datetime.now, verbose_name="学习时间")

    class Meta:
        verbose_name = "用户学习的课程"
        verbose_name_plural = verbose_name
